- To install a button, drop it onto a text window.
- To use a button, click it once. ("Use" means run the script of the button.)
- To get help about a particular button, select the "Help" item of its contextual menu.
- To pull down the contextual menu of a button, press the mouse button with the Control key depressed (Ctrl-click).
- To make a new button, drop "Empty button" onto a text window.
- To open the script of a button, click it once with the Command and Option key down ( click).
Several examples of custom buttons are presented, button example 1, button example 2 and button example 3 (we recommend starting with the button example 1).
Button Menus
Once a button is installed onto a window, use the contextual menu (Ctrl-click) on the button to reveal its menu. The button's menu includes the following items.
• Delete …
This menu item is described first because it may be most used choice. Selecting "Delete" deletes (uninstalls) the button from the window. The only action is the removing of the button from the window. The button file stored in the Smile folder is not deleted or altered in any way.
• Save as …
Selecting "Save as..." opens a dialog box that lets you assign a button file name and to choose a destination. Note that the button’s file name need not necessarily be the same as the name of the button itself.
• Help …
The "Help …" menu is provided and may provide a description of the action of the button. Additional information on the operation of the button may also be found in the Help file for that particular button.
• Edit button
Selecting this menu brings up a dialog box with a title that is the same name as the button’s ("Undo" in below example).
Name
The "Name" field allows for entering a new name or for editing the existing name. The button title can consist of letters, numbers, or other keyboard symbols. The entries that you make in the "Name" field will be immediately seen in the button itself. When you use the dialog to set the name of a button, Smile automatically adjusts the button size to accommodate the length of the title that you choose.
Changing the name of a button is a good idea when the function performed by the button script has been changed. The new name would then indicate the new function performed by the script.
Width
The "Width" field reads the width of the button’s name in pixels, and changes dynamically as changes are made in the "Name" field. As stated above, Smile automatically adjusts the button size to the entered button name. However, the width of the button may be set manually. This is done by entering a number directly in the "Width" field.
Installing a button
Buttons can only be installed onto text windows, not script windows. You may want to install a ready-made button, or an empty button, to make one of your own - and possibly save it to disk later. All sample buttons (empty and non-empty) can be found in the "Advanced stuff" folder.
To install a button onto a window, drag-and-drop the button onto the window (on the body of the window, not the title bar) and the button will automatically be installed. Multiple buttons can be installed on the same window.
Note : When a button is installed onto a window, the original button remains in place and can be used over and over again. Thus, the button is "copied" during installation, rather than "moved".
The first button is installed on the left, and subsequent buttons are arranged in a left to right order. Buttons can be installed in any order you chose.
Once a button is installed, it cannot be moved or copied to another position on the same window or another window by using drag-and-drop, or any other means.
Once buttons are installed, save the window to save the buttons that have been installed onto it. (Adding a button(s) is considered a change to the window.)
Saving the window assures that you will not have to reinstall the buttons.
Reminder : Do not get confused, the Smile buttons are for installation onto text windows only. They cannot be installed onto dialog boxes, and they are not for use with dialog boxes. For buttons in dialogs, see custom dialogs.
Scripting a button
Each button includes a script that will run when the button is clicked (assuming that the button is installed onto a window). To open the script, use click on the button (as in Hypercard).
The script of a button is a particular case of an object script.
You may want to write two handlers in the script of a button, "helpString" and "mouseUp".
The "helpString" handler is optional. It must return a short string (< 255 characters long) which will be displayed in a dialog box when the user selects the "Help" item of the contextual menu of the button. For a multilingual help, test the global variable "my language code" - 0 for US english and 1 for french.
The mouseUp handler is not optional. The action associated with clicking the button must be written in this handler.
----------------------------
on helpString(theButton)
-- make and return a short help string
end helpString
----------------------------
----------------------------
on mouseUp(theButton)
-- do the action
-- if needed, refer to the window as "container of theButton"
end mouseUp
----------------------------
Both handlers have one parameter, a reference to the button. Use the "container" property to refer to the window containing the button.
• Buttons can no longer be installed onto script windows (this was possible on versions before 1.6). This is because the script windows now have an (optional) comment pane.
• Buttons can be installed onto graphic windows. In graphic windows, buttons can be dragged by pressing the key while clicking (and holding) the mouse button. When dragging a button of a graphic window, you can :
- move it to a different location of the same window
- save it to disk
- copy it to another graphic window
- copy its reference to a text or script window
• Like almost every user action, the installation of buttons is scriptable. The general form of the script would look like this :
----------------------------
tell theWind to drop theFile onto it at somePt
----------------------------
where theFile is the path to the button, and "somePt" is any list of two integers such as {1,1}.
If you need to script the actual mechanism of adding and deleting buttons, please check the corresponding routines in the associated class scripts, "Button" and "Text window".